<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    img{
      width: 500px;
    }
  </style>
</head>
<body>
  <img alt="" id="img">
  <script>
    //异步加载图片
    const loadImgAsync=url=>{
      return new Promise((resolve,reject)=>{
        const img =new Image()
        img.onload=()=>{
          resolve(img)
        }
        img.onerror=()=>{
          reject(new Error(`Could not load image at ${url}`))
        }
        img.src=url
      })
    }
    const imgDOM=document.getElementById('img')
    loadImgAsync('https://img.mukewang.com/5e6af63d00011da318720764.jpg').then(img=>{
      console.log(img.src);
      setTimeout(() => {
        imgDOM.src=img.src
      }, 1000);
    }).catch(err=>console.log(err))
  </script>
</body>
</html>